CheckOpenPCT.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. %====================================================%
  2. % Check if parallel computing toolbox is available. %
  3. % If so, ask user and open a worker pool if desired. %
  4. % Last modified: Sept. 16, 2014 %
  5. %====================================================%
  6. % Copyright (C) 2013-2014, Michael J. Cheung
  7. %
  8. % This file is a part of the MEG & PLS Pipeline (MEGPLS). For more
  9. % details, see the documentation included with the software package.
  10. %
  11. % MEGPLS is free software: you can redistribute it and/or modify it under
  12. % the terms of the GNU General Public License version 2 as published by
  13. % the Free Software Foundation. This program is distributed in the hope
  14. % that it will be useful, but WITHOUT ANY WARRANTY; without even the
  15. % implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. % See the GNU General Public License for more details.
  17. %
  18. % You should have received a copy of the GNU General Public License along
  19. % with this program. If not, you can download the license here:
  20. % <http://www.gnu.org/licenses/old-licenses/gpl-2.0>.
  21. function CheckOpenPCT
  22. % Check if user has Parallel Computing Toolbox:
  23. Toolboxes = ver;
  24. if any(strcmp('Parallel Computing Toolbox', {Toolboxes.Name}))
  25. PCTavail = 1;
  26. else
  27. PCTavail = 0;
  28. return;
  29. end
  30. % If matlab pool is already open, return:
  31. if matlabpool('size') > 0
  32. return;
  33. end
  34. % Ask user and open matlab pool:
  35. if PCTavail == 1 && matlabpool('size') == 0
  36. prompt = {'MATLAB Parallel Computing Toolbox has been detected.';
  37. 'If available, [MEG]PLS supports parallel processing.'; '';
  38. 'Do you wish to open a worker pool for parallel computation?'; ''};
  39. OpenPool = questdlg(prompt, 'PARALLEL COMPUTING:', 'YES', 'NO', 'NO');
  40. if strcmp(OpenPool, 'NO')
  41. return;
  42. end
  43. CheckLicense = license('inuse', 'Parallel Computing Toolbox');
  44. if isempty(CheckLicense)
  45. license('checkout', 'Parallel Computing Toolbox');
  46. end
  47. NumWorkers = inputdlg...
  48. ('Enter # of Workers for Pool:', 'Num. Workers:', 1, {'2'});
  49. if isempty(NumWorkers)
  50. return; % If user cancels
  51. else
  52. NumWorkers = str2num(NumWorkers{1});
  53. end
  54. if isempty(NumWorkers) || length(NumWorkers) > 1
  55. error('Error: Input must be a single number.')
  56. end
  57. matlabpool('OPEN', NumWorkers)
  58. end